exports.install = function (Vue, options) {
    Vue.prototype.webname = "土豆集";
    Vue.prototype.alert = function (msg){
        layer.open({
            title: '温馨提示',
            content: msg
        });
    };
    Vue.prototype.toast = function (msg){
        layer.msg(msg, {time: 1000});
    };
    Vue.prototype.ok = function (msg){
        layer.msg(msg, {icon: 1});
    };
    Vue.prototype.error = function (msg){
        layer.msg(msg, {icon: 5});
    };

//实时更新storage值
    Vue.prototype.resetSetItem = function (key, newVal) {
        // 创建一个StorageEvent事件
        var newStorageEvent = document.createEvent('StorageEvent');
        const storage = {
            setItem: function (k, val) {
                sessionStorage.setItem(k, val);
                // 初始化创建的事件
                newStorageEvent.initStorageEvent('setItem', false, false, k, null, val, null, null);
                // 派发对象
                window.dispatchEvent(newStorageEvent)
            }
        }
        return storage.setItem(key, newVal);
    },

    //判断是否登录
    Vue.prototype.checkLogin = function() {
        this.$get('/system/Tuser!getPCuser.action')
            .then(response => {
                //前后端共同判断登录是否过期
                if (response.data.msg == 'false' || sessionStorage.getItem('permissions') ==  null) {
                    alert('会话已过期，请重新登录！')
                    this.$router.push({  name:'Login' })
                }
            });
    },
    //保留两位小数
    Vue.prototype.toFix2 = function(num) {
        return Math.round(num * 100) / 100;
    },
    //保留四位小数
    Vue.prototype.toFix4 = function(num) {
        return Math.round(num * 10000) / 10000;
    },
    Vue.prototype.back = function () {
        this.$parent.switchPage(this.$parent.refView);
    },
    Vue.prototype.serialize2Obj = function (data) {
        var obj = {};
        $.each(data,function(i,v){
            obj[v.name] = v.value;
        })
        return obj;
    },
    Vue.prototype.dateToValue = function(date) {
        let dateIt = new Date(date);
        return dateIt.valueOf();
    },
        //通用toast
        Vue.prototype.toastSuccess = function (text) {
            layer.msg(text, {time: 1000});
        },
        Vue.prototype.toastError = function (text) {
            layer.msg(text, {time: 1000});
        },
        Vue.prototype.toastText = function (text) {
            layer.msg(text, {time: 1000});
        },
        Vue.prototype.checkObjNull = function (val) {
            return val != undefined ? val : '';
        }

        // Vue.prototype.ajax = function (url, method, params, callback) {
        //     $.ajaxSetup({
        //         dataType: "json",
        //         cache: false,
        //         complete: function(xhr) {
        //             console.log('xhr:', xhr)
        //         }
        //     });
        // }
};
